package sword_to_1;

import java.util.Arrays;
import java.util.TreeMap;

public class LeeCode_60 {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(dicesProbability(1)));
        System.out.println(Arrays.toString(dicesProbability(2)));
    }
    private static double[] dicesProbability(int n) {
        TreeMap<Integer, Integer> map = new TreeMap<>();
        int tmp = 1;
        for (int i = 0; i < n; i++) {
            tmp *= 6;
        }
        dfs(map, 0,0, n);
        double[] ans = new double[map.size()];
        int i = 0;
        while (!map.isEmpty()){
            int son = map.pollFirstEntry().getValue();
            ans[i++] = (double) son / tmp;
        }
        return ans;
    }
    private static void dfs(TreeMap<Integer, Integer> map, int sum, int i, int n){
        if (i == n){
            if (map.containsKey(sum)){
                map.put(sum, map.get(sum) + 1);
            }else {
                map.put(sum, 1);
            }
            return;
        }
        for (int j = 1; j <= 6; j++) {
            dfs(map, sum + j, i + 1, n);
        }
    }
}
